import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_switch/flutter_switch.dart';

import 'KaL_Config.dart';

class FLSwitch extends StatefulWidget {
  FLSwitch({super.key, this.isOpen = false, required this.onPressed});

  bool? isOpen;
  final Function(bool) onPressed; // 回调函数

  @override
  State<FLSwitch> createState() => _FLSwitchState();
}

class _FLSwitchState extends State<FLSwitch> {
  bool SwitchStatus = false;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    SwitchStatus = widget.isOpen!;
    return Container(
      margin: const EdgeInsets.all(5),
      child: FlutterSwitch(
        width: 46,
        height: 26,
        toggleSize: 15,
        valueFontSize: 9,
        showOnOff: true,
        activeColor: KaL_Config.KaL_themeColor_HL,
        activeTextColor: Colors.white,
        inactiveTextColor: const Color.fromARGB(255, 62, 61, 61),
        value: SwitchStatus,
        onToggle: (val) {
          setState(() {
            SwitchStatus = val;
            widget.onPressed(val);
          });
        },
      ),
    );
  }
}
